package com.hfzy.ihk.web.file_upload.utils;

import com.hfzy.ihk.common.constants.GlobalStatic;
import com.hfzy.ihk.common.util.Utils;
import com.hfzy.ihk.common.web.WebResult;
import com.hfzy.ihk.web.file_upload.support.DefaultResult;
import com.hfzy.ihk.web.file_upload.vo.ResultVo;


import java.util.List;
import java.util.Map;

public class WebResultUtils {

    //FAIL_CHAR
    public static WebResult getFailCharWebResult(String failMsg){
        WebResult webResult = new WebResult();
        webResult.setCode(GlobalStatic.CODE_0);
        webResult.setMsg(!Utils.isNullString(failMsg)?failMsg:GlobalStatic.FAIL_CHAR);
        webResult.setTotal(0);
        webResult.setRecords(null);
        webResult.setParameter(null);
        return webResult;
    }

    //EXCEPTION_CHAR
    public static  WebResult getExceptionCharWebResult(String errorMsg){
        WebResult webResult = new WebResult();
        webResult.setCode(GlobalStatic.CODE_N);
        webResult.setMsg(!Utils.isNullString(errorMsg)?errorMsg:GlobalStatic.EXCEPTION_CHAR);
        webResult.setTotal(0);
        webResult.setRecords(null);
        webResult.setParameter(null);
        return webResult;
    }

    //SUCCESS_CHAR
    public static  WebResult getSuccessCharWebResult(String successMsg,long total,List records){
        WebResult webResult = new WebResult();
        webResult.setCode(GlobalStatic.CODE_1);
        webResult.setMsg(!Utils.isNullString(successMsg)?successMsg:GlobalStatic.SUCCESS_CHAR);
        webResult.setTotal(total);
        webResult.setRecords((records!=null && !records.isEmpty())?records:null);
        webResult.setParameter(null);
        return webResult;
    }


    public static DefaultResult getFailCharDefaultResulte(String failMsg){
        DefaultResult defaultResult = new DefaultResult();
        defaultResult.setCode(GlobalStatic.CODE_0);
        defaultResult.setMsg(!Utils.isNullString(failMsg)?failMsg:GlobalStatic.FAIL_CHAR);
        defaultResult.setData(null);
        return defaultResult;
    }

    public static DefaultResult getExceptionCharDefaultResulte(String exceptionMsg){
        DefaultResult defaultResult = new DefaultResult();
        defaultResult.setCode(GlobalStatic.CODE_N);
        defaultResult.setMsg(!Utils.isNullString(exceptionMsg)?exceptionMsg:GlobalStatic.EXCEPTION_CHAR);
        defaultResult.setData(null);
        return defaultResult;
    }


    public static DefaultResult getSuccessCharDefaultResulte(String successMsg,Map<String,Object> data){
        DefaultResult defaultResult = new DefaultResult();
        defaultResult.setCode(GlobalStatic.CODE_1);
        defaultResult.setMsg(!Utils.isNullString(successMsg)?successMsg:GlobalStatic.SUCCESS_CHAR);
        defaultResult.setData(data);
        return defaultResult;
    }


    public static ResultVo getFailCharResulteVo(String failMsg){
        ResultVo resultVo = new ResultVo();
        resultVo.setCode(GlobalStatic.CODE_0);
        resultVo.setMsg(!Utils.isNullString(failMsg)?failMsg:GlobalStatic.FAIL_CHAR);
        resultVo.setData(null);
        return resultVo;
    }

    public static ResultVo getExceptionCharResulteVo(String exceptionMsg){
        ResultVo resultVo = new ResultVo();
        resultVo.setCode(GlobalStatic.CODE_N);
        resultVo.setMsg(!Utils.isNullString(exceptionMsg)?exceptionMsg:GlobalStatic.EXCEPTION_CHAR);
        resultVo.setData(null);
        return resultVo;
    }


    public static ResultVo getSuccessCharResulteVo(String successMsg,Map<String,Object> data){
        ResultVo resultVo = new ResultVo();
        resultVo.setCode(GlobalStatic.CODE_1);
        resultVo.setMsg(!Utils.isNullString(successMsg)?successMsg:GlobalStatic.SUCCESS_CHAR);
        resultVo.setData(data);
        return resultVo;
    }
}
